# FILE: WeatherBroker.py
# DESC: obtains weather observation corresponding to geoname object 
#

# TODO: move to oreus.conf, context geonames


WEATHER_OBSERVATION_URL="http://ws.geonames.org/findNearByWeatherJSON?lat=%s&lng=%s&lang=%s"

from web.service.WebServiceBroker import WebServiceBroker


class WeatherBroker(WebServiceBroker):

	def getObservation(self, lat, lng, lang):
		observation = {}
		try:
			response = self.requestJSON(WEATHER_OBSERVATION_URL % (lat, lng, lang))
			if response and response.has_key('weatherObservation'):
				observation['clouds'] = response['weatherObservation']['clouds']
				observation['condition'] = response['weatherObservation']['weatherCondition']
				observation['temperature'] = response['weatherObservation']['temperature']
				observation['windSpeed'] = response['weatherObservation']['windSpeed']
				observation['datetime'] = response['weatherObservation']['datetime']
		except KeyError:
			pass
		
		except:
			raise

		return observation